package top.tupobi.zing.service.socket.packet;

import java.util.Date;

import top.tupobi.zing.InfoRecord;
import top.tupobi.zing.utils.MD5Utils;

public class SocketPacket {

    private int dataType;
    private int code;
    private String message;
    private String userId;
    private String timestamp;
    private String userName;
    private String token;

    private String data;

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public int getDataType() {
        return dataType;
    }

    public void setDataType(int dataType) {
        this.dataType = dataType;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }


    @Override
    public String toString() {
        return "SocketPacket{" +
                "dataType=" + dataType +
                ", code=" + code +
                ", message='" + message + '\'' +
                ", userId='" + userId + '\'' +
                ", timestamp='" + timestamp + '\'' +
                ", userName='" + userName + '\'' +
                ", token='" + token + '\'' +
                ", data='" + data + '\'' +
                '}';
    }

    public static SocketPacket createPacket(int dataType) {
        SocketPacket socketPacket = new SocketPacket();
        String timestamp = String.valueOf(new Date().getTime());
        String username = InfoRecord.getUsername();
        String id = InfoRecord.getUserId();
        socketPacket.setTimestamp(timestamp);
        socketPacket.setUserId(id);
        socketPacket.setUserName(username);
        socketPacket.setToken(MD5Utils.md5(id + timestamp + username));
        socketPacket.setDataType(dataType);
        return socketPacket;
    }
}